package com.prs.crm.dao.crm.impl;

import java.sql.SQLException;
import java.util.Collection;

import org.courser.Util;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.crm.FeedbackDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.crm.Feedback;
import com.prs.crm.domain.crm.Liaison;
import com.prs.crm.domain.hr.Person;

public class FeedbackDaoImpl extends BaseDaoImpl<Feedback> implements FeedbackDao{

	@Override
	@SuppressWarnings("unchecked")
	public Collection<Feedback> getFeedbackByReplyerInNow(final Person person) {
		// TODO Auto-generated method stub
		return (Collection<Feedback>) this.getHibernateTemplate().executeFind(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = arg0.createCriteria(Feedback.class);
				criteria.add(Restrictions.eq("replyer", person));
				criteria.add(Restrictions.le("replyDate", Util.nowFullTime()));
				criteria.addOrder(Order.desc("recordTime"));
				return criteria.list();
			}
			
		});
	}

	@Override
	public Collection<Feedback> getFeedbackByIds(Collection<Integer> ids) {
		// TODO Auto-generated method stub
		Criteria criteria = this.getSession().createCriteria(Feedback.class);
		criteria.add(Restrictions.in("id", ids));
		return criteria.list();
	}

}
